package com.cn.wanxi.servlet.company;

import com.alibaba.fastjson.JSONObject;
import com.cn.wanxi.model.CompanyModel;
import com.cn.wanxi.service.ICompanyService;
import com.cn.wanxi.service.impl.CompanyServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/back/company/update")
public class CompanyUpdateServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//       乱码
//        取值
        String idString = req.getParameter("id");

        String logo = req.getParameter("logo");
        String phone = req.getParameter("phone");
        String ad = req.getParameter("ad");
        String net = req.getParameter("net");
        String email = req.getParameter("email");
        String linePhone = req.getParameter("linePhone");
        String address = req.getParameter("address");
//        封装
        CompanyModel companyModel = new CompanyModel();
        companyModel.setLogo(logo);
        companyModel.setId(idString == null || "".equals(idString) ? 0 : Integer.parseInt(idString));
        companyModel.setAd(ad);
        ICompanyService companyService = new CompanyServiceImpl();
        int count = companyService.update(companyModel);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("count", count);
        resp.getWriter().println(jsonObject);
    }
}
